package cn.org.spring.wechar.prize.service.impl;

import cn.org.spring.common.util.StringUtil;
import cn.org.spring.wechar.constant.PrizeConstant;
import cn.org.spring.wechar.prize.entity.RecTelPrizeRecord;
import cn.org.spring.wechar.prize.mapper.RecTelPrizeRecordMapper;
import cn.org.spring.wechar.prize.service.RecTelPrizeRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author： 谢辉
 * @date： 2021/5/20
 * @email: xieh_mail@163.com
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@Slf4j
@Service
public class RecTelPrizeRecordServiceImpl implements RecTelPrizeRecordService {
    @Autowired
    RecTelPrizeRecordMapper recTelPrizeRecordMapper;


    @Override
    public RecTelPrizeRecord selectUnUsePrize(String openid) {
        if (StringUtil.isEmpty(openid)) {
            log.warn("查询用户可以使用的优惠券传入openid为空，不处理返回null");
            return null;
        }
        return recTelPrizeRecordMapper.selectUnUsePrize(openid);
    }

    @Override
    public int insert(RecTelPrizeRecord recTelPrizeRecord) {
        if (recTelPrizeRecord == null) {
            log.warn("新增抽奖记录信息为空，不处理直接返回");
            return 0;
        }
        return recTelPrizeRecordMapper.insert(recTelPrizeRecord);
    }

    @Override
    public int update(RecTelPrizeRecord recTelPrizeRecord) {
        if (recTelPrizeRecord == null || recTelPrizeRecord.getId() == null) {
            log.warn("更新抽奖记录信息为空，不处理直接返回");
            return 0;
        }
        return recTelPrizeRecordMapper.update(recTelPrizeRecord);
    }
}
